package geppetto.phraseTable.phrase.feature.calc.local;

import geppetto.phraseHMM.phraseExtraction.extractedphrase.ExtractedPhrasePairData;
import geppetto.phraseHMM.phraseExtraction.extractedphrase.data.LexicalWeightData;
import geppetto.phraseTable.phrase.Phrase;
import geppetto.phraseTable.phrase.feature.AbstractFeature;
import geppetto.phraseTable.phrase.feature.LexicalWeightingFeature;
import geppetto.phraseTable.phrase.feature.ProbabilityFeature;

import java.util.ArrayList;
import java.util.HashMap;


public class LexicalWeightingFeatureCalc implements AbstractFeatureCalc{
	
	protected final static String LEXICAL_WEIGHITING = "lexical_weight";
	protected final static String REVERSE_LEXICAL_WEIGHTING = "lexical_weight_reverse";
	protected final static String FEATURE = "lweight";
	protected final static String FEATURE_2 = "rlweight";
	protected boolean reverse = false;
	protected boolean shouldPrint = true;
	protected int order;

	public LexicalWeightingFeatureCalc(int order, boolean reverse, boolean shouldPrint) {
		super();
		this.reverse = reverse;
		this.order = order;
		this.shouldPrint = shouldPrint;
	}

	public LexicalWeightingFeatureCalc(int order, boolean reverse) {
		super();
		this.reverse = reverse;
		this.order = order;
	}

	public boolean isReverse() {
		return reverse;
	}

	public void setReverse(boolean reverse) {
		this.reverse = reverse;
	}

	@Override
	public void calculateFeature(ArrayList<Phrase> phrases) {
		String field = LEXICAL_WEIGHITING;
		String feature = FEATURE;
		if(reverse){
			field = REVERSE_LEXICAL_WEIGHTING;
			feature = FEATURE_2;
		}
		for(int i = 0; i < phrases.size(); i++){
			Phrase p = phrases.get(i);
			double lexical = ((LexicalWeightData)p.getData(field)).getLexicalWeighting();
			phrases.get(i)._features.addFeature(feature,new LexicalWeightingFeature(lexical), order);
		}
	}

}
